﻿import QtQuick 2.0
import QtQuick.Window 2.2
import "."
import "QChart.js"        as Charts
import "QChartGallery.js" as ChartsData
Rectangle {
    property int px:0
    property int py:0
    property bool show:false
    property var enterpriseInfor: ""
     property double ratio:1.25
    property var  dustArray: ""
    property var  so2Array: ""
    property var  nosArray: ""
    id:root
    width: 811
    height: 469
    color:"transparent"
    visible:show
//    visible: true
    Image{
    width:parent.width
    height:parent.height
    source:"./切图/企业信息/底子.png"
    }
    MouseArea
    {
        anchors.fill: parent
    }

    Component.onCompleted:
    {
        var zzz = "{\"x\" :\"22\",
\"y\" :\"22\",
\"data\":{\"area\":0,\"attention\":\"国控\",\"city\":\"安阳市\",\"if30\":\"\",\"industry\":\"炼焦\",\"lat\":36.21596,\"lon\":114.05874,\"pollutants\":\"烟尘；二氧化硫；氮氧化物\",\"psclass\":\"污水处理厂\",\"pscode\":\"410500000819\",\"psname\":\"河南省顺成集团煤焦有限公司\",\"region\":\"安阳市\",\"unit\":\"县以上工业企业\"
,\"last7day\":{\"dust\":[0,0,0,0,0,0,0],\"so2\":[0,0,0,0,0,0,0],\"nos\":[0,1,2,3,24,5,7]}
}
}"
        enterpriseInfor =JSON.parse(zzz)
//        var dust_max =0
//        var so2_max =0
//        var nos_max =0
//        for(var i = 0;i<enterpriseInfor.data.last7day.dust.length;i++)
//        {
//            if(parseFloat(enterpriseInfor.data.last7day.dust[i])>dust_max)
//            {
//                dust_max = parseFloat(enterpriseInfor.data.last7day.dust[i])
//            }
//        }
//        for(var i1 = 0;i1<enterpriseInfor.data.last7day.so2.length;i1++)
//        {
//            if(parseFloat(enterpriseInfor.data.last7day.so2[i1])>so2_max)
//            {
//                so2_max = parseFloat(enterpriseInfor.data.last7day.so2[i1])
//            }
//        }
//        for(var i2 = 0;i2<enterpriseInfor.data.last7day.nos.length;i2++)
//        {
//            if(parseFloat(enterpriseInfor.data.last7day.nos[i2])>nos_max)
//            {
//                nos_max = parseFloat(enterpriseInfor.data.last7day.nos[i2])
//            }
//        }
//        var u = [65,59,90,81,56,55,40]


        var u1 = enterpriseInfor.data.last7day.dust
        var u2 = enterpriseInfor.data.last7day.so2
        var u3 = enterpriseInfor.data.last7day.nos
        dustArray = {
              labels: ["1","2","3","4","5","6","7"],
            datasets: [{
                    fillColor: "transparent",
                    strokeColor: "yellow",
                    pointColor: "yellow",
                pointStrokeColor: "#ffffff",
                            data: u1
            }]
        }
        so2Array = {
              labels: ["1","2","3","4","5","6","7"],
            datasets: [{
                    fillColor: "transparent",
                    strokeColor: "green",
                    pointColor: "green",
                pointStrokeColor: "#ffffff",
                            data: u2
            }]
        }
        nosArray = {
              labels: ["1","2","3","4","5","6","7"],
            datasets: [{
                    fillColor: "transparent",
                    strokeColor: "red",
                    pointColor: "red",
                pointStrokeColor: "#ffffff",
                            data: u3
            }]
        }
    }

    Image{
        id:closeIco
        source:"./切图/弹窗/关闭未点击.png"
        anchors.right:parent.right
        anchors.top:parent.top
        anchors.rightMargin:20
        anchors.topMargin:20

        MouseArea{
            hoverEnabled: true
            anchors.fill:parent
            onEntered: closeIco.source="./切图/弹窗/关闭点击.png"
            onExited:  closeIco.source="./切图/弹窗/关闭未点击.png"
            onClicked: {
                show=false;
            }
        }
    }
    Row
    {
        id: titleRow
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 30
        spacing: 8
        Image{
            id:qiyeImage
            source:"./切图/企业信息/企业.png"
        }
        Rectangle {
            width: cityImage.width
            height: qiyeImage.height
            color: "transparent"
            Text{
                id:cityImage
                text:"企业详细信息"
                font.pixelSize: 18
                color:"white"
                font.family: "微软雅黑"
                font.underline:true
                lineHeightMode:Text.FixedHeight
            }
            MouseArea
            {
                id:cityImageArea
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: cityImageArea.containsMouse ? Qt.PointingHandCursor :Qt.ArrowCursor
                onPressed:
                {
//                    if(enterpriseInfor.data.pscode === "410100001748")
//                    {
//                         mainApp.slotSmogBuild(true)
//                         emit: openSliverTime()
//                    }


                }
            }
        }
    }

    Row
    {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: titleRow.bottom
        anchors.topMargin: 10
        spacing: 8
        Rectangle
        {
            width: 469
            height: 391
            color: "transparent"
            Image {
                id: pictureBack
                source: "./切图/企业信息/表格.png"
                anchors.centerIn: parent
                Rectangle
                {
                    id:rec01
//                    width: 169
                    width: 94
                    height: 391
                    color: "transparent"
                    anchors.top: parent.top
                    anchors.left: parent.left
                    Column
                    {
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"企业名称"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                               anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"监测等级"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"单位地址"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"所在地"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"单位类别"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"行业类别"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"污染类型"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                        Rectangle
                        {
                            width: 94
                            height: 391/8
                            color: "transparent"
                            Text{
                                text:"主要排放物"
                                font.pixelSize: 18
                                color:"white"
                                font.family: "微软雅黑"
                                anchors.centerIn: parent
                            }
                        }
                    }

                }
                Rectangle
                {
                    id:rec02
                    width: 375
                    height: 391
                    anchors.top: parent.top
                    anchors.left: rec01.right
                     color: "transparent"
                     Column
                     {
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.psname
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.attention
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.region
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.city
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.unit
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.industry
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.psclass
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                         Rectangle
                         {
                             width: 375
                             height: 391/8
                             color: "transparent"
                             Text{
                                 text:enterpriseInfor.data.pollutants
                                 font.pixelSize: 18
                                 color:"white"
                                 font.family: "微软雅黑"
                                 anchors.centerIn: parent
                             }
                         }
                     }

                }


            }
        }
        Rectangle
        {
            width: 320
            height: 391
            color: "transparent"
            Text{
                id:text001
                text:"近一周排污染物放量 ："
                font.pixelSize: 18
                color:"white"
                font.family: "微软雅黑"
                anchors.left: parent.left
                anchors.top:  parent.top

            }
//            Item
            Rectangle
            {
                id:xiantiaoImage01
                width: 301
                height: 70
                anchors.top: text001.bottom
                anchors.left: text001.left
                anchors.topMargin: 10
                color: "transparent"
//                Image {
//                    id: iamge001
//                    source: "./切图/企业信息/黄.png"
//                    anchors.fill: parent
//                }
                QChart {
                    anchors.centerIn: parent
                  id: chart_line;
                //      width: chart_width;
                //      height: chart_height;
                  width: parent.width;
                  height: parent.height;
                  chartAnimated: true;
                  chartAnimationEasing: Easing.InOutElastic;
                //      chartAnimationDuration: 2000;
                   chartAnimationDuration: 0;
                //      chartData: ChartsData.ChartLineData;
                   chartData: dustArray
                  chartType: Charts.ChartType.LINE;
                }
            }
            Text{
                id:text002
                text:"烟尘"
                font.pixelSize: 18
                color:"white"
                font.family: "微软雅黑"
                anchors.top:  xiantiaoImage01.bottom
                anchors.topMargin: 10
                anchors.horizontalCenter: xiantiaoImage01.horizontalCenter

            }

            //Item
            Rectangle
            {
                id:xiantiaoImage02
                width: 301
                height: 70
                anchors.top: text002.bottom
                anchors.left: xiantiaoImage01.left
                anchors.topMargin: 26
                color: "transparent"
//                Image {
//                    id: iamge002
//                    source: "./切图/企业信息/绿.png"
//                    anchors.fill: parent
//                }
                QChart {
                    anchors.centerIn: parent
                  id: chart02_line;
                //      width: chart_width;
                //      height: chart_height;
                  width: parent.width;
                  height: parent.height;
                  chartAnimated: true;
                  chartAnimationEasing: Easing.InOutElastic;
                //      chartAnimationDuration: 2000;
                   chartAnimationDuration: 0;
                //      chartData: ChartsData.ChartLineData;
                   chartData: so2Array
                  chartType: Charts.ChartType.LINE

                }

            }
            Text{
                id:text003
                text:"二氧化硫"
                font.pixelSize: 18
                color:"white"
                font.family: "微软雅黑"
                anchors.top:  xiantiaoImage02.bottom
                anchors.topMargin: 10
                anchors.horizontalCenter: xiantiaoImage02.horizontalCenter

            }

//            Item
            Rectangle
            {
                id:xiantiaoImage03
                width: 301
                height: 70
                anchors.top: text003.bottom
                anchors.left: xiantiaoImage02.left
                anchors.topMargin: 26
                color: "transparent"
//                Image {
//                    id: iamge003
//                    source: "./切图/企业信息/红.png"
//                    anchors.fill: parent
//                }
                QChart {
                    anchors.centerIn: parent
                  id: chart03_line;
                //      width: chart_width;
                //      height: chart_height;
                  width: parent.width;
                  height: parent.height;
                  chartAnimated: true;
                  chartAnimationEasing: Easing.InOutElastic;
                //      chartAnimationDuration: 2000;
                   chartAnimationDuration: 0;
                //      chartData: ChartsData.ChartLineData;
                   chartData: nosArray
                  chartType: Charts.ChartType.LINE;
                }
            }
            Text{
                id:text004
                text:"氮氧化物"
                font.pixelSize: 18
                color:"white"
                font.family: "微软雅黑"
                anchors.top:  xiantiaoImage03.bottom
                anchors.topMargin: 10
                anchors.horizontalCenter: xiantiaoImage03.horizontalCenter

            }



        }

    }

     Connections
     {
         target:app
         //信号调用处
         onSignalShowPSInfo:
         {
              enterpriseInforUpdate(msg);
         }
     }
     Connections
     {
         target:earthView
         onSignalCloseAnnoInfo:
         {
             show=false;
         }
     }


    function enterpriseInforUpdate(data)
    {
        enterpriseInfor = JSON.parse(data);
        if(enterpriseInfor.length===0){
            show=false;
        }
        else{
            var x = enterpriseInfor.x
            var y = enterpriseInfor.y

            if(Screen.width - x <= root.width && y <= root.height)
            {
                px =  x - root.width
                py =  y
            }
            else if(x <= root.width && Screen.height - y <= root.height-39)
            {
                px =  x
                py =  y - root.height
            }
            else if(Screen.width - x <= root.width && Screen.height - y <= root.height-39)
            {
                px =  x - root.width
                py =  y - root.height
            }
            else if(Screen.width - x <= root.width )
            {
                px =  x - root.width
                py =  y - root.height
            }
            else if(Screen.height - y <= root.height-39)
            {
                px =  x
                py =  y - root.height
            }
            else if(x <= root.width && y > root.height)
            {
                px =  x
                py =  y - root.height
            }
            else
            {
                px =  x
                py =  y
            }
//            var u1 = enterpriseInfor.data.last7day.dust

//            var u2 = enterpriseInfor.data.last7day.so2
//            var u3 = enterpriseInfor.data.last7day.nos
            var u1 = enterpriseInfor.data.last7day.dust

            var u2 = enterpriseInfor.data.last7day.so2
            var u3 = enterpriseInfor.data.last7day.nos
            chart_line.chartData.datasets[0].data = u1;
            chart02_line.chartData.datasets[0].data = u2;
            chart03_line.chartData.datasets[0].data = u3;
            chart_line.requestPaint()
            chart02_line.requestPaint()
            chart03_line.requestPaint()
//            dustArray = {
//                  labels: ["1","2","3","4","5","6","7"],
//                datasets: [{
//                        fillColor: "transparent",
//                        strokeColor: "yellow",
//                        pointColor: "yellow",
//                    pointStrokeColor: "#ffffff",
//                                data: u1
//                }]
//            }
//            so2Array = {
//                  labels: ["1","2","3","4","5","6","7"],
//                datasets: [{
//                        fillColor: "transparent",
//                        strokeColor: "green",
//                        pointColor: "green",
//                    pointStrokeColor: "#ffffff",
//                                data: u2
//                }]
//            }
//            nosArray = {
//                  labels: ["1","2","3","4","5","6","7"],
//                datasets: [{
//                        fillColor: "transparent",
//                        strokeColor: "red",
//                        pointColor: "red",
//                    pointStrokeColor: "#ffffff",
//                                data: u3
//                }]
//            }

            show=true;

        }


    }


}

